package com.lottemall.item.mapper;

import com.lottemall.common.mapper.BaseMapper;
import com.lottemall.item.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 品牌Mapper接口
 *
 * 中间表是tb_category_brand
 */
public interface BrandMapper extends BaseMapper<Brand> {
    /**
     * 新增商品分类和品牌的中间表数据
     * @param cid 商品分类id
     * @param bid 品牌id
     * @return
     */
    @Insert("INSERT INTO tb_category_brand (category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertCategoryBrand(@Param("cid")Long cid,@Param("bid") Long bid);

    /**
     * 根据商品类型cid查询品牌，需要通过中间表，这里使用左连接查询
     * @param cid
     * @return
     */
    @Select("SELECT b.* FROM tb_brand b LEFT JOIN tb_category_brand cb ON b.id = cb.brand_id WHERE cb.category_id = #{cid}")
    List<Brand> queryByCategoryId(@Param("cid") Long cid);
}
